
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>2.2 MQ · Ebook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="zq_sdk@163.com">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-disqus/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tree/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-ace/ace.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex/katex.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../../program/" />
    
    
    <link rel="prev" href="socket.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"repo":"TIME-GATE/","types":["star","watch"],"size":"large"};
    </script>

    
    <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chart/c3/c3.min.css">
    <script src="../../gitbook/gitbook-plugin-chart/c3/d3.min.js"></script>
    <script src="../../gitbook/gitbook-plugin-chart/c3/c3.min.js"></script>
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="../../about_me.html">
            
                <a href="../../about_me.html">
            
                    
                    关于
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2" data-path="../../gitbook_install.html">
            
                <a href="../../gitbook_install.html">
            
                    
                    附:Gitbook安装
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../">
            
                <a href="../../">
            
                    
                    一 基础理论
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../data_structure/">
            
                <a href="../../data_structure/">
            
                    
                    1 数据结构
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="../../data_structure/11_linear_structure.html">
            
                <a href="../../data_structure/11_linear_structure.html">
            
                    
                    1.1 数组、链表、跳表及字典
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1.1" data-path="../../data_structure/111_array.html">
            
                <a href="../../data_structure/111_array.html">
            
                    
                    1.1.1 数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.1.2" data-path="../../data_structure/112_link_list.html">
            
                <a href="../../data_structure/112_link_list.html">
            
                    
                    1.1.2 链表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.1.3" data-path="../../data_structure/113_skip_list.html">
            
                <a href="../../data_structure/113_skip_list.html">
            
                    
                    1.1.3 跳表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.1.4" data-path="../../data_structure/114_dictionary.html">
            
                <a href="../../data_structure/114_dictionary.html">
            
                    
                    1.1.4 字典
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="../../data_structure/12_stack_and_queue.html">
            
                <a href="../../data_structure/12_stack_and_queue.html">
            
                    
                    1.2 栈、队列、散列及集合
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.2.1" data-path="../../data_structure/121_stack.html">
            
                <a href="../../data_structure/121_stack.html">
            
                    
                    1.2.1 栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2.2" data-path="../../data_structure/122_queue.html">
            
                <a href="../../data_structure/122_queue.html">
            
                    
                    1.2.2 队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2.3" data-path="../../data_structure/123_hash.html">
            
                <a href="../../data_structure/123_hash.html">
            
                    
                    1.2.3 散列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2.4" data-path="../../data_structure/124_set.html">
            
                <a href="../../data_structure/124_set.html">
            
                    
                    1.2.4 集合
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.1.3" data-path="../../data_structure/13_tree_and_forest.html">
            
                <a href="../../data_structure/13_tree_and_forest.html">
            
                    
                    1.3 树与森林
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.3.1" data-path="../../data_structure/131.html">
            
                <a href="../../data_structure/131.html">
            
                    
                    1.3.1 二叉搜索树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.3.2" data-path="../../data_structure/132.html">
            
                <a href="../../data_structure/132.html">
            
                    
                    1.3.2 红黑树
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.1.4" data-path="../../data_structure/14_map.html">
            
                <a href="../../data_structure/14_map.html">
            
                    
                    1.4 图结构
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.4.1" data-path="../../data_structure/141_minimal_tree.html">
            
                <a href="../../data_structure/141_minimal_tree.html">
            
                    
                    1.4.1 最小生成树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.4.2" data-path="../../data_structure/142_single_source_shortest_path.html">
            
                <a href="../../data_structure/142_single_source_shortest_path.html">
            
                    
                    1.4.2 单源最短路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.4.3" data-path="../../data_structure/143_all_source_shortest_path.html">
            
                <a href="../../data_structure/143_all_source_shortest_path.html">
            
                    
                    1.4.3 多源最短路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.4.4" data-path="../../data_structure/144_max_stream.html">
            
                <a href="../../data_structure/144_max_stream.html">
            
                    
                    1.4.4 最大流
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../">
            
                <a href="../../">
            
                    
                    2 基础算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../../algorithm/21.html">
            
                <a href="../../algorithm/21.html">
            
                    
                    2.1 排序查找
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="../../algorithm/22.html">
            
                <a href="../../algorithm/22.html">
            
                    
                    2.2 动态规划
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../algorithm/distributed_algorithm.html">
            
                <a href="../../algorithm/distributed_algorithm.html">
            
                    
                    3 分布式算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="../ci_deplopment/cs/theory.html">
            
                <a href="../ci_deplopment/cs/theory.html">
            
                    
                    3.1 一致性模式与理论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="../../algorithm/raft.html">
            
                <a href="../../algorithm/raft.html">
            
                    
                    3.2 Raft协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.3" data-path="../../algorithm/paxos.html">
            
                <a href="../../algorithm/paxos.html">
            
                    
                    3.3 Paxos协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.4" data-path="../../algorithm/gossip.html">
            
                <a href="../../algorithm/gossip.html">
            
                    
                    3.4 Gossip协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.5" data-path="../ci_deplopment/cs/plan.html">
            
                <a href="../ci_deplopment/cs/plan.html">
            
                    
                    3.5 几种一致性方案
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../optimization_se/">
            
                <a href="../../optimization_se/">
            
                    
                    4 运筹及系统工程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.4.1" data-path="../../optimization_se/linear_programming.html">
            
                <a href="../../optimization_se/linear_programming.html">
            
                    
                    4.1 线性规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.2" data-path="../../optimization_se/integer_programming.html">
            
                <a href="../../optimization_se/integer_programming.html">
            
                    
                    4.2 整数规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.3" data-path="../../optimization_se/目标规划.html">
            
                <a href="../../optimization_se/目标规划.html">
            
                    
                    4.3 目标规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.4" data-path="../../optimization_se/非线性规划.html">
            
                <a href="../../optimization_se/非线性规划.html">
            
                    
                    4.4 非线性规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.5" data-path="../../optimization_se/动态规划.html">
            
                <a href="../../optimization_se/动态规划.html">
            
                    
                    4.5 动态规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.6" data-path="../../optimization_se/排队论.html">
            
                <a href="../../optimization_se/排队论.html">
            
                    
                    4.6 排队论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.7" data-path="../../optimization_se/博弈论.html">
            
                <a href="../../optimization_se/博弈论.html">
            
                    
                    4.7 博弈论
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    二 工程应用
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../design_pattern/">
            
                <a href="../design_pattern/">
            
                    
                    1 设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1.1" data-path="../design_pattern/strategy.html">
            
                <a href="../design_pattern/strategy.html">
            
                    
                    1.1 策略模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.2" data-path="../design_pattern/prototype.html">
            
                <a href="../design_pattern/prototype.html">
            
                    
                    1.2 原型模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.3" data-path="../design_pattern/singleton.html">
            
                <a href="../design_pattern/singleton.html">
            
                    
                    1.3 单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.4" data-path="../design_pattern/factory.html">
            
                <a href="../design_pattern/factory.html">
            
                    
                    1.4 工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.5" data-path="../design_pattern/bridge.html">
            
                <a href="../design_pattern/bridge.html">
            
                    
                    1.5 桥接模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.6" data-path="../design_pattern/composite.html">
            
                <a href="../design_pattern/composite.html">
            
                    
                    1.6 组合模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.7" data-path="../design_pattern/facade.html">
            
                <a href="../design_pattern/facade.html">
            
                    
                    1.7 门面模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.8" data-path="../design_pattern/adapter.html">
            
                <a href="../design_pattern/adapter.html">
            
                    
                    1.8 适配器模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.9" data-path="../design_pattern/decorator.html">
            
                <a href="../design_pattern/decorator.html">
            
                    
                    1.9 装饰者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.10" data-path="../design_pattern/flyweight.html">
            
                <a href="../design_pattern/flyweight.html">
            
                    
                    1.10 享元模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.11" data-path="../design_pattern/proxy.html">
            
                <a href="../design_pattern/proxy.html">
            
                    
                    1.11 代理模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.12" data-path="../design_pattern/middleware.html">
            
                <a href="../design_pattern/middleware.html">
            
                    
                    1.12 中间件模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="./">
            
                <a href="./">
            
                    
                    2 网络编程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.1" data-path="socket.html">
            
                <a href="socket.html">
            
                    
                    2.1 长连接
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.2.2" data-path="mq.html">
            
                <a href="mq.html">
            
                    
                    2.2 MQ
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../program/">
            
                <a href="../../program/">
            
                    
                    3 语言应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.3.1" data-path="../../program/nodejs/node.html">
            
                <a href="../../program/nodejs/node.html">
            
                    
                    3.1 Node.js
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.3.1.1" data-path="../../program/nodejs/core.html">
            
                <a href="../../program/nodejs/core.html">
            
                    
                    3.1.1 原理及构成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.2" data-path="../../program/nodejs/async.html">
            
                <a href="../../program/nodejs/async.html">
            
                    
                    3.1.2 异步机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.3" data-path="../../program/nodejs/important.html">
            
                <a href="../../program/nodejs/important.html">
            
                    
                    3.1.3 一些核心概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.4" data-path="../../program/nodejs/koa_web.html">
            
                <a href="../../program/nodejs/koa_web.html">
            
                    
                    3.1.4 web应用: koa框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.5" data-path="../../program/nodejs/koa.html">
            
                <a href="../../program/nodejs/koa.html">
            
                    
                    3.1.5 koa源码分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.6" data-path="../../program/nodejs/libuv.html">
            
                <a href="../../program/nodejs/libuv.html">
            
                    
                    3.1.6 libuv网络库应用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.7" data-path="../../program/nodejs/apm.html">
            
                <a href="../../program/nodejs/apm.html">
            
                    
                    3.1.7 性能调优
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.8" data-path="../../program/nodejs/node_spider.html">
            
                <a href="../../program/nodejs/node_spider.html">
            
                    
                    3.1.8 其他: Node爬虫
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.1.9" data-path="../../program/nodejs/node_map_reduce.html">
            
                <a href="../../program/nodejs/node_map_reduce.html">
            
                    
                    3.1.9 其他: Node编写Mapreduce
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.3.2" data-path="../../program/c/c_and_plus.html">
            
                <a href="../../program/c/c_and_plus.html">
            
                    
                    3.2 C/C++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.3.2.1" data-path="../../program/c/oop.html">
            
                <a href="../../program/c/oop.html">
            
                    
                    3.2.1 面向对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.2" data-path="../../program/c/ipcs.html">
            
                <a href="../../program/c/ipcs.html">
            
                    
                    3.2.2 进程通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.3" data-path="../../program/c/thread.html">
            
                <a href="../../program/c/thread.html">
            
                    
                    3.2.3 线程管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.4" data-path="../../program/c/memory.html">
            
                <a href="../../program/c/memory.html">
            
                    
                    3.2.4 内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.5" data-path="../../program/c/network.html">
            
                <a href="../../program/c/network.html">
            
                    
                    3.2.5 网络编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.6" data-path="../../program/c/build_tool.html">
            
                <a href="../../program/c/build_tool.html">
            
                    
                    3.2.6 构建工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2.7" data-path="../../program/c/thread_pool.html">
            
                <a href="../../program/c/thread_pool.html">
            
                    
                    3.2.7 其他: 线程池
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../ci_deplopment/">
            
                <a href="../ci_deplopment/">
            
                    
                    三 搭建部署
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../ci_deplopment/test.html">
            
                <a href="../ci_deplopment/test.html">
            
                    
                    3.1 测试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1.1" data-path="../ci_deplopment/test/unit_testing.html">
            
                <a href="../ci_deplopment/test/unit_testing.html">
            
                    
                    3.1.1 单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.2" data-path="../ci_deplopment/test/stress_testing.html">
            
                <a href="../ci_deplopment/test/stress_testing.html">
            
                    
                    3.1.2 压力测试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../ci_deplopment/ci_readme.html">
            
                <a href="../ci_deplopment/ci_readme.html">
            
                    
                    3.2 集成
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../ci_deplopment/ci/gitlab_ci.html">
            
                <a href="../ci_deplopment/ci/gitlab_ci.html">
            
                    
                    3.2.1 GitLab CI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="../ci_deplopment/ci/spinnaker.html">
            
                <a href="../ci_deplopment/ci/spinnaker.html">
            
                    
                    3.2.2 Spinnaker
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../ci_deplopment/build.html">
            
                <a href="../ci_deplopment/build.html">
            
                    
                    3.3 部署
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.3.1" data-path="../ci_deplopment/k8s/k8s.html">
            
                <a href="../ci_deplopment/k8s/k8s.html">
            
                    
                    3.3.1 k8s
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3.2" data-path="../ci_deplopment/rancher/rancher.html">
            
                <a href="../ci_deplopment/rancher/rancher.html">
            
                    
                    3.3.2 rancher
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3.3" data-path="../ci_deplopment/swarm/swarm.html">
            
                <a href="../ci_deplopment/swarm/swarm.html">
            
                    
                    3.3.3 swarm
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../ci_deplopment/maintenance.html">
            
                <a href="../ci_deplopment/maintenance.html">
            
                    
                    3.4 监控
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.4.1" data-path="../ci_deplopment/monitor.html">
            
                <a href="../ci_deplopment/monitor.html">
            
                    
                    3.4.1 容器监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4.2" data-path="../ci_deplopment/trace.html">
            
                <a href="../ci_deplopment/trace.html">
            
                    
                    3.4.2 系统监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4.3" data-path="../ci_deplopment/app1.md">
            
                <span>
            
                    
                    3.4.2 应用监控
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../ha/ha.html">
            
                <a href="../ha/ha.html">
            
                    
                    3.5 高可用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.5.1" data-path="../ha/client.html">
            
                <a href="../ha/client.html">
            
                    
                    3.5.1 接入层高可用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.2" data-path="../ha/service.html">
            
                <a href="../ha/service.html">
            
                    
                    3.5.2 服务层高可用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.3" data-path="../ha/share.html">
            
                <a href="../ha/share.html">
            
                    
                    3.5.3 存储层高可用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../ci_deplopment/hc/hc.html">
            
                <a href="../ci_deplopment/hc/hc.html">
            
                    
                    3.6 高并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.6.1" data-path="../ci_deplopment/hc/dns.html">
            
                <a href="../ci_deplopment/hc/dns.html">
            
                    
                    3.6.1 基于DNS的负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6.2" data-path="../ci_deplopment/hc/lvs.html">
            
                <a href="../ci_deplopment/hc/lvs.html">
            
                    
                    3.6.2 基于Lvs的负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6.3" data-path="../ci_deplopment/hc/haproxy.html">
            
                <a href="../ci_deplopment/hc/haproxy.html">
            
                    
                    3.6.3 基于haproxy的负载均衡
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    四 架构模式
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" >
            
                <span>
            
                    
                    1 微服务架构设计与实践
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1.1" data-path="../../program/java/spring-cloud.html">
            
                <a href="../../program/java/spring-cloud.html">
            
                    
                    1.1 微服务概况
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.2" data-path="../../program/java/spring-eureka.html">
            
                <a href="../../program/java/spring-eureka.html">
            
                    
                    1.2 服务注册及发现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.3" data-path="../../program/java/spring-feign.html">
            
                <a href="../../program/java/spring-feign.html">
            
                    
                    1.3 服务调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.4" data-path="../../program/java/spring-zuul.html">
            
                <a href="../../program/java/spring-zuul.html">
            
                    
                    1.4 网关及负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.5" data-path="../../program/java/spring-hystrix.html">
            
                <a href="../../program/java/spring-hystrix.html">
            
                    
                    1.5 熔断、限流、扩缩容
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.6" data-path="../../program/java/spring-config.html">
            
                <a href="../../program/java/spring-config.html">
            
                    
                    1.6 云配置中心
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.7" data-path="../../program/java/zipkin-tracing.html">
            
                <a href="../../program/java/zipkin-tracing.html">
            
                    
                    1.7 分布式链路追踪
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.1.8" data-path="../../program/java/swagger.html">
            
                <a href="../../program/java/swagger.html">
            
                    
                    1.8 接口文档管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../domain/">
            
                <a href="../../domain/">
            
                    
                    2 领域驱动模型
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.2.1" data-path="../../domain/domain.html">
            
                <a href="../../domain/domain.html">
            
                    
                    2.1 领域--Domain
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.2" data-path="../../domain/entity.md">
            
                <span>
            
                    
                    2.2 领域实体--Entity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.3" data-path="../../domain/object.html">
            
                <a href="../../domain/object.html">
            
                    
                    2.3 值对象--Value Object
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.4" data-path="../../domain/aggregate.html">
            
                <a href="../../domain/aggregate.html">
            
                    
                    2.4 聚合--Aggregate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.5" data-path="../../domain/service.html">
            
                <a href="../../domain/service.html">
            
                    
                    2.5 服务--Services
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.6" data-path="../../domain/event.html">
            
                <a href="../../domain/event.html">
            
                    
                    2.6 领域事件--Event
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2.7" data-path="../../domain/framework.html">
            
                <a href="../../domain/framework.html">
            
                    
                    2.7 几种常见的DDD架构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5.3" >
            
                <span>
            
                    
                    3 架构技术的演化与趋势
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.3.1" >
            
                <span>
            
                    
                    3.1 架构技术的发展历史及现状
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3.2" >
            
                <span>
            
                    
                    3.2 Serverless无服务架构概念
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3.3" >
            
                <span>
            
                    
                    3.3 ServerMesh网格服务概念
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    五 其他
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../../story/talk.html">
            
                <a href="../../story/talk.html">
            
                    
                    5.1 小伙子,放松!
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >2.2 MQ</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="mq&#x5206;&#x7C7B;">MQ&#x5206;&#x7C7B;</h2>
<pre><code>1&#x3001;Rabbitmq: 
2&#x3001;Mqtt: 
3&#x3001;Kafka:
</code></pre><hr>
<h3 id="&#x4E00;&#x3001;rabbitmq">&#x4E00;&#x3001;Rabbitmq</h3>
<p>&#xA0;&#xA0;&#xA0;&#xA0;MQ&#x5168;&#x79F0;&#x4E3A;Message Queue, &#x6D88;&#x606F;&#x961F;&#x5217;&#xFF08;MQ&#xFF09;&#x662F;&#x4E00;&#x79CD;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x5BF9;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x901A;&#x4FE1;&#x65B9;&#x6CD5;&#x3002;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x901A;&#x8FC7;&#x8BFB;&#x5199;&#x51FA;&#x5165;&#x961F;&#x5217;&#x7684;&#x6D88;&#x606F;&#xFF08;&#x9488;&#x5BF9;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x6570;&#x636E;&#xFF09;&#x6765;&#x901A;&#x4FE1;&#xFF0C;&#x800C;&#x65E0;&#x9700;&#x4E13;&#x7528;&#x8FDE;&#x63A5;&#x6765;&#x94FE;&#x63A5;&#x5B83;&#x4EEC;&#x3002;&#x6D88;&#x606F;&#x4F20;&#x9012;&#x6307;&#x7684;&#x662F;&#x7A0B;&#x5E8F;&#x4E4B;&#x95F4;&#x901A;&#x8FC7;&#x5728;&#x6D88;&#x606F;&#x4E2D;&#x53D1;&#x9001;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x901A;&#x4FE1;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x901A;&#x8FC7;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x5F7C;&#x6B64;&#x6765;&#x901A;&#x4FE1;&#xFF0C;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x901A;&#x5E38;&#x662F;&#x7528;&#x4E8E;&#x8BF8;&#x5982;&#x8FDC;&#x7A0B;&#x8FC7;&#x7A0B;&#x8C03;&#x7528;&#x7684;&#x6280;&#x672F;&#x3002;&#x6392;&#x961F;&#x6307;&#x7684;&#x662F;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x901A;&#x8FC7;&#x961F;&#x5217;&#x6765;&#x901A;&#x4FE1;&#x3002;&#x961F;&#x5217;&#x7684;&#x4F7F;&#x7528;&#x9664;&#x53BB;&#x4E86;&#x63A5;&#x6536;&#x548C;&#x53D1;&#x9001;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x540C;&#x65F6;&#x6267;&#x884C;&#x7684;&#x8981;&#x6C42;&#xFF0C;MQ&#x6D88;&#x606F;&#x961F;&#x5217;&#x591A;&#x7528;&#x5728;&#x7CFB;&#x7EDF;&#x89E3;&#x8026;&#x4E2D;&#xFF0C;&#x5982;Spring cloud&#x7684;&#x6D88;&#x606F;&#x603B;&#x7EBF;&#x673A;&#x5236;&#x3002;</p>
<h4 id="11&#x3001;&#x642D;&#x5EFA;&#x5355;&#x8282;&#x70B9;rabbitmq">1.1&#x3001;&#x642D;&#x5EFA;&#x5355;&#x8282;&#x70B9;Rabbitmq</h4>
<pre><code class="lang-bash">docker pull rabbitmq

docker run <span class="hljs-_">-d</span> --name rabbitmq -p 5673:5672 -p 15673:15672 rabbitmq:3-management

user: guest
password: guest

http://127.0.0.1:15673/<span class="hljs-comment">#/</span>
</code></pre>
<h4 id="12&#x3001;&#x5E38;&#x89C1;&#x672F;&#x8BED;&#x4E0E;&#x6D88;&#x606F;&#x6D41;&#x7A0B;">1.2&#x3001;&#x5E38;&#x89C1;&#x672F;&#x8BED;&#x4E0E;&#x6D88;&#x606F;&#x6D41;&#x7A0B;</h4>
<p><img src="http://cdn.find-world.top/mq_1.png" alt="mq_1"></p>
<pre><code>1&#x3001;Connection&#xFF1A;&#x4E0E;RabbitMQ&#x670D;&#x52A1;&#x5668;&#x7684;&#x8FDE;&#x63A5;
2&#x3001;Channel&#xFF1A;&#x4E0E;Exchange&#x8FDE;&#x63A5;
3&#x3001;Exchange&#xFF1A;&#x63A5;&#x53D7;&#x6D88;&#x606F;&#x63D0;&#x4F9B;&#x8005;&#x7684;&#x6D88;&#x606F;&#xFF0C;&#x5E76;&#x6839;&#x636E;&#x6D88;&#x606F;RoutingKey&#x548C;Exchange&#x7ED1;&#x5B9A;&#x5206;&#x914D;&#x6D88;&#x606F;
4&#x3001;Queue&#xFF1A;&#x5B58;&#x50A8;&#x6D88;&#x606F;&#x63A5;&#x6536;&#x8005;&#x7684;&#x6D88;&#x606F;
5&#x3001;RoutingKey&#xFF1A;&#x6307;&#x5B9A;&#x5F53;&#x524D;Exchange&#x4E0B;&#xFF0C;&#x6839;&#x636E;RoutingKey&#x4E0B;&#x6D3E;&#x5230;&#x5F53;&#x524D;&#x7ED1;&#x5B9A;&#x7684;Queue&#x4E2D;
</code></pre><h4 id="13&#x3001;&#x56DB;&#x79CD;&#x4EA4;&#x6362;&#x673A;&#x7C7B;&#x578B;">1.3&#x3001;&#x56DB;&#x79CD;&#x4EA4;&#x6362;&#x673A;&#x7C7B;&#x578B;</h4>
<p>&#xA0;&#xA0;&#xA0;&#xA0;&#x4EA4;&#x6362;&#x673A;&#x7C7B;&#x578B;type&#x53EF;&#x7406;&#x89E3;&#x4E3A;RoutingKey&#x4E0E;queue&#x5728;&#x7ED1;&#x5B9A;&#x65F6;&#x7684;&#x6620;&#x5C04;&#x89C4;&#x5219;&#xFF0C;&#x4E0D;&#x901A;&#x7684;&#x6620;&#x5C04;&#x89C4;&#x5219;&#x51B3;&#x5B9A;&#x4E86;&#x5982;&#x4F55;&#x9AD8;&#x6548;&#x5730;&#x5C06;&#x751F;&#x4EA7;&#x7684;&#x6D88;&#x606F;&#x63A8;&#x9001;&#x5230;&#x961F;&#x5217;&#x3002;</p>
<pre><code>- direct

  Publish message&#x65F6;&#x9700;&#x6307;&#x5B9A;RoutingKey&#x3002;&#x9ED8;&#x8BA4;&#x5219;&#x53D1;&#x9001;&#x5230;&#x7B2C;&#x4E00;&#x4E2A;&#x4E0D;&#x7528;RoutingKey&#x7ED1;&#x5B9A;&#x7684;queue&#xFF1B;&#x6307;&#x5B9A;
RoutingKey&#x5219;&#x53D1;&#x9001;&#x5230;&#x7ED1;&#x5B9A;&#x7684;&#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x4E00;&#x4E2A;RoutingKey&#x53EF;&#x4EE5;&#x7ED1;&#x5B9A;&#x5230;&#x591A;&#x4E2A;queue

- topic
  Publish message&#x65F6;&#x9700;&#x6307;&#x5B9A;RoutingKey&#xFF0C;&#x53D1;&#x9001;&#x65F6;&#x53D1;&#x9001;&#x5230;&#x901A;&#x914D;&#x7B26;&#x7B26;&#x5408;&#x7684;&#x961F;&#x5217;&#x4E2D;&#xFF0C;&#x5982;RoutingKey=hello.#&#x3002;&#x9ED8;&#x8BA4;
&#x5219;&#x53D1;&#x9001;&#x5230;&#x7B2C;&#x4E00;&#x4E2A;&#x4E0D;&#x7528;RoutingKey&#x7ED1;&#x5B9A;&#x7684;queue&#x4E2D;

- fanout 
  Publish message&#x65F6;&#x4E0D;&#x5904;&#x7406;&#x8DEF;&#x7531;&#x952E;&#xFF0C;&#x5C06;queue&#x7ED1;&#x5B9A;&#x5230;exchange&#x4E0A;&#xFF0C;exchange&#x7684;&#x6D88;&#x606F;&#x90FD;&#x4F1A;&#x88AB;&#x8F6C;&#x53D1;&#x5230;&#x4E0E;&#x8BE5;exchange
&#x7ED1;&#x5B9A;&#x7684;&#x6240;&#x6709;&#x961F;&#x5217;&#x4E0A;&#x3002;Fanout&#x7C7B;&#x578B;&#x7684;Exchange&#x8F6C;&#x53D1;&#x6D88;&#x606F;&#x662F;&#x6700;&#x5FEB;&#x7684;

- headers 
  Publish message&#x65F6;&#x4E0D;&#x5904;&#x7406;&#x8DEF;&#x7531;&#x952E;&#xFF0C;&#x800C;&#x662F;&#x6839;&#x636E;&#x53D1;&#x9001;&#x7684;&#x6D88;&#x606F;&#x5185;&#x5BB9;&#x4E2D;&#x7684;headers&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x5339;&#x914D;&#x3002;&#x5728;&#x7ED1;&#x5B9A;Queue&#x4E0E;
Exchange&#x65F6;&#x6307;&#x5B9A;&#x4E00;&#x7EC4;&#x952E;&#x503C;&#x5BF9;&#xFF1B;&#x5F53;&#x6D88;&#x606F;&#x53D1;&#x9001;&#x5230;RabbitMQ&#x65F6;&#x4F1A;&#x53D6;&#x5230;&#x8BE5;&#x6D88;&#x606F;&#x7684;headers&#x4E0E;Exchange&#x7ED1;&#x5B9A;&#x65F6;&#x6307;&#x5B9A;&#x7684;&#x952E;&#x503C;&#x5BF9;&#x8FDB;
&#x884C;&#x5339;&#x914D;&#xFF1B;&#x5982;&#x679C;&#x5B8C;&#x5168;&#x5339;&#x914D;&#x5219;&#x6D88;&#x606F;&#x4F1A;&#x8DEF;&#x7531;&#x5230;&#x8BE5;&#x961F;&#x5217;&#xFF0C;&#x5426;&#x5219;&#x4E0D;&#x4F1A;&#x8DEF;&#x7531;&#x5230;&#x8BE5;&#x961F;&#x5217;&#x3002;
</code></pre><h4 id="14&#x3001;&#x5E94;&#x7528;&#x4E3E;&#x4F8B;">1.4&#x3001;&#x5E94;&#x7528;&#x4E3E;&#x4F8B;</h4>
<p>&#x5C01;&#x88C5;mqlib.js&#x6A21;&#x5757;&#x5982;&#x4E0B;:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> amqp = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;amqplib&apos;</span>);
<span class="hljs-keyword">const</span> EventEmitter = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;events&apos;</span>);

<span class="hljs-keyword">let</span> connectCounter = <span class="hljs-number">1</span>;

<span class="hljs-comment">/* &#x95ED;&#x5305;:&#x5171;&#x4EAB;&#x8FDE;&#x63A5; */</span>
<span class="hljs-keyword">const</span> connect = (config) =&gt; {
  <span class="hljs-keyword">var</span> [conn, channel] = [<span class="hljs-literal">null</span>, <span class="hljs-literal">null</span>];

  <span class="hljs-keyword">return</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;Connect Counter:&apos;</span>, connectCounter++);
    conn = <span class="hljs-keyword">await</span> amqp.connect(config);
    channel = <span class="hljs-keyword">await</span> conn.createChannel();

    <span class="hljs-keyword">return</span> {conn, channel}
  }
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Queue</span> </span>{
  <span class="hljs-keyword">constructor</span>(config) {
    <span class="hljs-keyword">this</span>.config = config;
    <span class="hljs-keyword">this</span>.conn = <span class="hljs-literal">null</span>;
    <span class="hljs-keyword">this</span>.channel = <span class="hljs-literal">null</span>;
    <span class="hljs-keyword">this</span>.isConnect = <span class="hljs-literal">false</span>;
    <span class="hljs-keyword">this</span>.consumeEmitter = <span class="hljs-keyword">new</span> EventEmitter();
  }

  <span class="hljs-keyword">async</span> connect() {
    <span class="hljs-keyword">const</span> ctx = <span class="hljs-keyword">await</span> (connect(<span class="hljs-keyword">this</span>.config))();
    <span class="hljs-keyword">this</span>.conn = ctx.conn;
    <span class="hljs-keyword">this</span>.channel = ctx.channel;
    <span class="hljs-keyword">this</span>.isConnect = <span class="hljs-literal">true</span>;
  }

  <span class="hljs-keyword">async</span> reconnect(reason) {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`mq connect <span class="hljs-subst">${reason}</span> , reconnect <span class="hljs-subst">${new Date()}</span>`</span>)
    <span class="hljs-keyword">await</span> (connect(<span class="hljs-keyword">this</span>.config))();
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.consumeEmitter.emit(<span class="hljs-string">&apos;consume&apos;</span>);
  }

  onError() {
    <span class="hljs-keyword">this</span>.conn.on(<span class="hljs-string">&apos;error&apos;</span>, (err) =&gt; {
      <span class="hljs-keyword">this</span>.isConnect = <span class="hljs-literal">false</span>
      setTimeout(<span class="hljs-keyword">async</span> () =&gt; {
        <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.reconnect(<span class="hljs-string">&apos;error&apos;</span>)
      }, <span class="hljs-number">1000</span>);
    });
  }

  onClose() {
    <span class="hljs-keyword">this</span>.conn.on(<span class="hljs-string">&apos;close&apos;</span>, (err) =&gt; {
      <span class="hljs-keyword">this</span>.isConnect = <span class="hljs-literal">false</span>
      setTimeout(<span class="hljs-keyword">async</span> () =&gt; {
        <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.reconnect(<span class="hljs-string">&apos;close&apos;</span>);
      }, <span class="hljs-number">1000</span>);
    })
  }

  <span class="hljs-keyword">async</span> init() {
    <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.isConnect) {
      <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.connect();
    }

    <span class="hljs-keyword">const</span> connEventNames = <span class="hljs-keyword">this</span>.conn.eventNames();

    <span class="hljs-keyword">if</span>(connEventNames.indexOf(<span class="hljs-string">&apos;error&apos;</span>) === <span class="hljs-number">-1</span>) {
      <span class="hljs-keyword">this</span>.onError();
    }

    <span class="hljs-keyword">if</span>(connEventNames.indexOf(<span class="hljs-string">&apos;close&apos;</span>) === <span class="hljs-number">-1</span>) {
      <span class="hljs-keyword">this</span>.onClose();
    }

  }

  <span class="hljs-comment">/**
   * close connection
   */</span>
  <span class="hljs-keyword">async</span> destroy() {
    <span class="hljs-keyword">this</span>.isConnect = <span class="hljs-literal">false</span>;
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.conn.close();
  }

  <span class="hljs-comment">/**
   * connect exchange
   */</span>
  <span class="hljs-keyword">async</span> getExchange(exchangeName, type = <span class="hljs-string">&apos;direct&apos;</span>, options = {durable: <span class="hljs-literal">true</span>}) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.channel.assertExchange(exchangeName, type, options);
  }

  <span class="hljs-comment">/**
   * connect queue
   */</span>
  <span class="hljs-keyword">async</span> getQueue(queueName, options = {exclusive: <span class="hljs-literal">false</span>}) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.channel.assertQueue(queueName, options);
  }

  <span class="hljs-comment">/**
   * bind handle
   */</span>
  <span class="hljs-keyword">async</span> bindHandle(operation, exName, quName, routingKey, options) {
    <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.init();

    <span class="hljs-keyword">const</span> ex = <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.getExchange(exName, <span class="hljs-string">&apos;direct&apos;</span>, options);
    <span class="hljs-keyword">const</span> qu = <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.getQueue(quName, options);

    <span class="hljs-keyword">switch</span> (operation) {
      <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;bind&apos;</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.channel.bindQueue(qu.queue, ex.exchange, routingKey); 
      <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;unbind&apos;</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.channel.unbindQueue(qu.queue, ex.exchange, routingKey);       
      <span class="hljs-keyword">default</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;  
    }
  }

  <span class="hljs-comment">/**
   * consume msg and add lisentner
   */</span>
  <span class="hljs-keyword">async</span> onConsume(ags) {
    <span class="hljs-keyword">const</span> consumeEventNames = <span class="hljs-keyword">this</span>.consumeEmitter.eventNames();

    <span class="hljs-keyword">if</span>(consumeEventNames.indexOf(<span class="hljs-string">&apos;consume&apos;</span>) &gt; <span class="hljs-number">-1</span>) {
      <span class="hljs-keyword">return</span>;
    }

    <span class="hljs-keyword">this</span>.consumeEmitter.on(<span class="hljs-string">&apos;consume&apos;</span>, <span class="hljs-keyword">async</span> () =&gt; {
      <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.channel.consume(ags[<span class="hljs-number">0</span>], <span class="hljs-keyword">async</span> (msg) =&gt; { 
        <span class="hljs-keyword">await</span> ags[<span class="hljs-number">1</span>](msg.content.toString(), ags[<span class="hljs-number">0</span>]);
        <span class="hljs-keyword">if</span>(ags[<span class="hljs-number">2</span>] &amp;&amp; !ags[<span class="hljs-number">2</span>].noAck) {
          <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.channel.ack(msg);
        }
      }, ags[<span class="hljs-number">2</span>]);
    })

    <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.consumeEmitter.emit(<span class="hljs-string">&apos;consume&apos;</span>);
  }

  <span class="hljs-keyword">async</span> msgHandle(operation, ...ags) {
    <span class="hljs-keyword">try</span> {
      <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.init();

      <span class="hljs-keyword">switch</span> (operation) {
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;produce&apos;</span>:
          <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.channel.publish(...ags);
        <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;consume&apos;</span>:
          <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.onConsume(ags);
        <span class="hljs-keyword">default</span>:
          <span class="hljs-keyword">return</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;choose operation?&apos;</span>);
      }
    } <span class="hljs-keyword">catch</span> (error) {
      <span class="hljs-keyword">return</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;handle error&apos;</span>, error);
    }
  }

  <span class="hljs-keyword">async</span> bindQueue(exName, quName, routingKey, options) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.bindHandle(<span class="hljs-string">&apos;bind&apos;</span>, exName, quName, routingKey, options);
  }

  <span class="hljs-keyword">async</span> unbindQueue(exName, quName, routingKey, options) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.bindHandle(<span class="hljs-string">&apos;unbind&apos;</span>, exName, quName, routingKey, options);
  }

  <span class="hljs-keyword">async</span> produce(exName, routingKey, msg) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.msgHandle(<span class="hljs-string">&apos;produce&apos;</span>, exName, routingKey, msg);
  }

  <span class="hljs-keyword">async</span> consume(quName, cb, options = {noAck: <span class="hljs-literal">true</span>}) {
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-keyword">this</span>.msgHandle(<span class="hljs-string">&apos;consume&apos;</span>, quName, cb, options);
  }

}

<span class="hljs-built_in">module</span>.exports = config =&gt; <span class="hljs-keyword">new</span> Queue(config);
</code></pre>
<ul>
<li>PUSH&#x6D88;&#x606F;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> mq = {
  hostname: <span class="hljs-string">&apos;127.0.0.1&apos;</span>,
  port: <span class="hljs-number">5672</span>,
  username: <span class="hljs-string">&apos;spero&apos;</span>,
  password: <span class="hljs-string">&apos;777&apos;</span>,
  authMechanism: <span class="hljs-string">&apos;AMQPLAIN&apos;</span>,
  vhost: <span class="hljs-string">&quot;spero&quot;</span>,
  connectionTimeout: <span class="hljs-number">1000</span>,
  heartbeat: <span class="hljs-number">60</span>,
  ssl: {
    enabled: <span class="hljs-literal">false</span>,
  },
};

<span class="hljs-keyword">const</span> amqp = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;mqlib&apos;</span>)(mq)

<span class="hljs-keyword">const</span> config = {
  a: {
    queueName: <span class="hljs-string">&apos;spero.a.msg.queue&apos;</span>,
    exchangeName: <span class="hljs-string">&apos;spero.app.msg.exchange&apos;</span>,
    routingKey: <span class="hljs-string">&apos;spero.a.msg.key&apos;</span>,
  },
  b: {
    queueName: <span class="hljs-string">&apos;spero.b.msg.queue&apos;</span>,
    exchangeName: <span class="hljs-string">&apos;spero.app.msg.exchange&apos;</span>,
    routingKey: <span class="hljs-string">&apos;spero.a.msg.key&apos;</span>,
  }
}

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mqFn</span>(<span class="hljs-params">...ags</span>) </span>{  

  <span class="hljs-comment">/* &#x7ED1;&#x5B9A;&#x961F;&#x5217;a */</span>
  <span class="hljs-keyword">await</span> amqp.bindQueue(
    config.a.exchangeName,
    config.a.queueName,
    config.a.routingKey
  );

  <span class="hljs-comment">/* &#x7ED1;&#x5B9A;&#x961F;&#x5217;b */</span>
  <span class="hljs-keyword">await</span> amqp.bindQueue(
    config.b.exchangeName,
    config.b.queueName,
    config.b.routingKey
  );

  <span class="hljs-comment">/* &#x901A;&#x8FC7;&#x4EA4;&#x6362;&#x673A;&#x540C;&#x65F6;&#x8DEF;&#x7531;&#x5230;&#x961F;&#x5217;a&#x3001;b */</span>
  <span class="hljs-keyword">await</span> amqp.produce(
    config.a.exchangeName,
    config.a.routingKey,
    <span class="hljs-keyword">new</span> Buffer(<span class="hljs-built_in">JSON</span>.stringify({msg: <span class="hljs-string">&apos;hello spero&apos;</span>}))
  );

  <span class="hljs-comment">/* &#x6D88;&#x8D39;&#x961F;&#x5217;a */</span>
  <span class="hljs-keyword">await</span> amqp.consume(
    config.a.queueName,
    consumeCb,
  );

  <span class="hljs-comment">/* &#x6D88;&#x8D39;&#x961F;&#x5217;b */</span>
  <span class="hljs-keyword">await</span> amqp.consume(
    config.b.queueName,
    consumeCb,
  );
}

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">consumeCb</span>(<span class="hljs-params">msg, quName</span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`from <span class="hljs-subst">${quName}</span> message: <span class="hljs-subst">${msg}</span>`</span>)
}

mqFn()
</code></pre>
<ul>
<li>&#x6253;&#x5370;&#x6D88;&#x606F;</li>
</ul>
<pre><code>master:node-common-tools dreamboad$ node test1.js
from spero.a.msg.queue message: {&quot;msg&quot;:&quot;hello spero&quot;}
from spero.b.msg.queue message: {&quot;msg&quot;:&quot;hello spero&quot;}
</code></pre><h4 id="15&#x3001;&#x6CE8;&#x610F;&#x4E8B;&#x9879;">1.5&#x3001;&#x6CE8;&#x610F;&#x4E8B;&#x9879;</h4>
<pre><code>1&#x3001; &#x6D88;&#x8D39;&#x8005;&#x5DE5;&#x4F5C;&#x673A;&#x9700;&#x8981;&#x5411;&#x670D;&#x52A1;&#x5668;&#x4E0D;&#x65AD;&#x53D1;&#x9001;&#x5FC3;&#x8DF3;&#x5305;&#xFF0C;&#x624D;&#x80FD;&#x4FDD;&#x8BC1;&#x6D88;&#x606F;&#x88AB;&#x6B63;&#x786E;&#x8DEF;&#x7531;, &#x6B64;mqlib&#x5E93;&#x9700;&#x81EA;&#x884C;&#x5B9E;&#x73B0;&#x91CD;&#x8FDE;&#x673A;&#x5236;
2&#x3001; &#x9700;&#x8981;&#x6D88;&#x606F;&#x786E;&#x8BA4;&#x673A;&#x5236;(ack)&#xFF0C;&#x4FDD;&#x8BC1;&#x5728;&#x5B95;&#x673A;&#x7B49;&#x6D88;&#x606F;&#x6CA1;&#x6709;&#x786E;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x80FD;&#x88AB;&#x91CD;&#x65B0;&#x52A0;&#x5165;&#x5230;&#x961F;&#x5217;
3&#x3001; rabbitmq&#x96C6;&#x7FA4;&#x6D88;&#x606F;&#x9700;&#x8981;&#x6301;&#x4E45;&#x5316;&#x624D;&#x80FD;&#x4FDD;&#x8BC1;&#x4EE5;&#x4E0A;&#x6D88;&#x606F;&#x6700;&#x7EC8;&#x88AB;&#x6D88;&#x8D39;&#x7B49;
</code></pre><hr>
<h3 id="&#x4E8C;&#x3001;mqtt">&#x4E8C;&#x3001;MQTT</h3>
<p>&#xA0;&#xA0;&#xA0;&#xA0;MQTT&#xFF08;Message Queuing Telemetry Transport&#xFF0C;&#x6D88;&#x606F;&#x961F;&#x5217;&#x9065;&#x6D4B;&#x4F20;&#x8F93;&#xFF09;&#x662F;IBM&#x5F00;&#x53D1;&#x7684;&#x4E00;&#x4E2A;&#x5373;&#x65F6;&#x901A;&#x8BAF;&#x534F;&#x8BAE;&#xFF0C;&#x6709;&#x53EF;&#x80FD;&#x6210;&#x4E3A;&#x7269;&#x8054;&#x7F51;&#x7684;&#x91CD;&#x8981;&#x7EC4;&#x6210;&#x90E8;&#x5206;&#x3002;&#x8BE5;&#x534F;&#x8BAE;&#x652F;&#x6301;&#x6240;&#x6709;&#x5E73;&#x53F0;&#xFF0C;&#x51E0;&#x4E4E;&#x53EF;&#x4EE5;&#x628A;&#x6240;&#x6709;&#x8054;&#x7F51;&#x7269;&#x54C1;&#x548C;&#x5916;&#x90E8;&#x8FDE;&#x63A5;&#x8D77;&#x6765;&#xFF0C;&#x88AB;&#x7528;&#x6765;&#x5F53;&#x505A;&#x4F20;&#x611F;&#x5668;&#x548C;&#x5236;&#x52A8;&#x5668;&#xFF08;&#x6BD4;&#x5982;&#x901A;&#x8FC7;Twitter&#x8BA9;&#x623F;&#x5C4B;&#x8054;&#x7F51;&#xFF09;&#x7684;&#x901A;&#x4FE1;&#x534F;&#x8BAE;&#x3002;MQTT&#x6709;&#x4E09;&#x79CD;&#x6D88;&#x606F;&#x53D1;&#x5E03;&#x670D;&#x52A1;&#x8D28;&#x91CF;&#xFF1A;</p>
<pre><code>&#x81F3;&#x591A;&#x4E00;&#x6B21;: &#x6D88;&#x606F;&#x53D1;&#x5E03;&#x5B8C;&#x5168;&#x4F9D;&#x8D56;&#x5E95;&#x5C42; TCP/IP &#x7F51;&#x7EDC;&#x3002;&#x4F1A;&#x53D1;&#x751F;&#x6D88;&#x606F;&#x4E22;&#x5931;&#x6216;&#x91CD;&#x590D;&#x3002;&#x53EF;&#x7528;&#x4E8E;&#x73AF;&#x5883;&#x4F20;&#x611F;&#x5668;&#x6570;&#x636E;&#xFF0C;&#x4E22;&#x5931;
&#x4E00;&#x6B21;&#x8BFB;&#x8BB0;&#x5F55;&#x65E0;&#x6240;&#x8C13;&#xFF0C;&#x56E0;&#x4E3A;&#x4E0D;&#x4E45;&#x540E;&#x8FD8;&#x4F1A;&#x6709;&#x7B2C;&#x4E8C;&#x6B21;&#x53D1;&#x9001;&#x3002;
&#x81F3;&#x5C11;&#x4E00;&#x6B21;: &#x786E;&#x4FDD;&#x6D88;&#x606F;&#x5230;&#x8FBE;&#xFF0C;&#x4F46;&#x6D88;&#x606F;&#x91CD;&#x590D;&#x53EF;&#x80FD;&#x4F1A;&#x53D1;&#x751F;&#x3002;
&#x53EA;&#x6709;&#x4E00;&#x6B21;: &#x786E;&#x4FDD;&#x6D88;&#x606F;&#x5230;&#x8FBE;&#x4E00;&#x6B21;&#x3002;&#x8FD9;&#x4E00;&#x7EA7;&#x522B;&#x53EF;&#x7528;&#x4E8E;&#x5982;&#x4E0B;&#x60C5;&#x51B5;&#xFF0C;&#x5728;&#x8BA1;&#x8D39;&#x7CFB;&#x7EDF;&#x4E2D;&#xFF0C;&#x6D88;&#x606F;&#x91CD;&#x590D;&#x6216;&#x4E22;&#x5931;&#x4F1A;&#x5BFC;&#x81F4;&#x4E0D;&#x6B63;&#x786E;&#x7684;&#x7ED3;&#x679C;&#x3002;
</code></pre><h4 id="21&#x3001;&#x642D;&#x5EFA;&#x5355;&#x8282;&#x70B9;mqtt">2.1&#x3001;&#x642D;&#x5EFA;&#x5355;&#x8282;&#x70B9;mqtt</h4>
<pre><code class="lang-bash">docker run -p 1883:1883  ncarlier/mqtt:latest
</code></pre>
<h4 id="22-&#x5E94;&#x7528;&#x4E3E;&#x4F8B;">2.2 &#x5E94;&#x7528;&#x4E3E;&#x4F8B;</h4>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> mqtt = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;mqtt&apos;</span>)

<span class="hljs-comment">/**
 * qos:
 *  0 &#x53D1;&#x9001;&#x8005;&#x53EA;&#x53D1;&#x9001;&#x4E00;&#x6B21;&#x6D88;&#x606F;&#xFF0C;&#x4E0D;&#x8FDB;&#x884C;&#x91CD;&#x8BD5;&#xFF0C;Broker&#x4E0D;&#x4F1A;&#x8FD4;&#x56DE;&#x786E;&#x8BA4;&#x6D88;&#x606F;
 *  1 &#x53D1;&#x9001;&#x8005;&#x6700;&#x5C11;&#x53D1;&#x9001;&#x4E00;&#x6B21;&#x6D88;&#x606F;&#xFF0C;&#x786E;&#x4FDD;&#x6D88;&#x606F;&#x5230;&#x8FBE;Broker&#xFF0C;Broker&#x9700;&#x8981;&#x8FD4;&#x56DE;&#x786E;&#x8BA4;&#x6D88;&#x606F;PUBACK
 *  2 Qos2&#x4F7F;&#x7528;&#x4E24;&#x9636;&#x6BB5;&#x786E;&#x8BA4;&#x6765;&#x4FDD;&#x8BC1;&#x6D88;&#x606F;&#x7684;&#x4E0D;&#x4E22;&#x5931;&#x548C;&#x4E0D;&#x91CD;&#x590D;
 */</span>
<span class="hljs-keyword">const</span> client  = mqtt.connect(<span class="hljs-string">&apos;mqtt://127.0.0.1:1883&apos;</span>, {
  username: <span class="hljs-string">&apos;admin&apos;</span>,
  password: <span class="hljs-string">&apos;admin&apos;</span>,
  qos: <span class="hljs-number">2</span>
})

client.on(<span class="hljs-string">&apos;connect&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  client.subscribe(<span class="hljs-string">&apos;presence&apos;</span>)
})

client.on(<span class="hljs-string">&apos;message&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">topic, message</span>) </span>{
  <span class="hljs-built_in">console</span>.log(message.toString())
})

setInterval(() =&gt; {
  client.publish(<span class="hljs-string">&apos;presence&apos;</span>, <span class="hljs-string">&apos;Hello mqtt&apos;</span>)
}, <span class="hljs-number">1500</span>)

process.on(<span class="hljs-string">&apos;exit&apos;</span>, (code) =&gt; {

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;MQTT DISCONNECT&apos;</span>)  
  client.end()

})
</code></pre>
<ul>
<li>&#x6253;&#x5370;&#x6D88;&#x606F;</li>
</ul>
<pre><code class="lang-bash">Dreamboad:Test helloworld$ node mqtt.js 
Hello mqtt
Hello mqtt
Hello mqtt
Hello mqtt
</code></pre>
<h4 id="25-&#x9002;&#x7528;&#x573A;&#x666F;">2.5 &#x9002;&#x7528;&#x573A;&#x666F;</h4>
<pre><code>1&#x3001;&#x4F7F;&#x7528;&#x53D1;&#x5E03;/&#x8BA2;&#x9605;&#x6D88;&#x606F;&#x6A21;&#x5F0F;&#xFF0C;&#x63D0;&#x4F9B;&#x4E00;&#x5BF9;&#x591A;&#x7684;&#x6D88;&#x606F;&#x53D1;&#x5E03;&#xFF0C;&#x89E3;&#x9664;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x8026;&#x5408;&#xFF1B;
2&#x3001;&#x5BF9;&#x8D1F;&#x8F7D;&#x5185;&#x5BB9;&#x5C4F;&#x853D;&#x7684;&#x6D88;&#x606F;&#x4F20;&#x8F93;&#xFF1B;
3&#x3001;&#x4F7F;&#x7528; TCP/IP &#x63D0;&#x4F9B;&#x7F51;&#x7EDC;&#x8FDE;&#x63A5;&#xFF1B;
4&#x3001;&#x5C0F;&#x578B;&#x4F20;&#x8F93;&#xFF0C;&#x5F00;&#x9500;&#x5F88;&#x5C0F;&#xFF08;&#x56FA;&#x5B9A;&#x957F;&#x5EA6;&#x7684;&#x5934;&#x90E8;&#x662F; 2 &#x5B57;&#x8282;&#xFF09;&#xFF0C;&#x534F;&#x8BAE;&#x4EA4;&#x6362;&#x6700;&#x5C0F;&#x5316;&#xFF0C;&#x4EE5;&#x964D;&#x4F4E;&#x7F51;&#x7EDC;&#x6D41;&#x91CF;&#xFF1B;
5&#x3001;&#x4F7F;&#x7528; Last Will &#x548C; Testament &#x7279;&#x6027;&#x901A;&#x77E5;&#x6709;&#x5173;&#x5404;&#x65B9;&#x5BA2;&#x6237;&#x7AEF;&#x5F02;&#x5E38;&#x4E2D;&#x65AD;&#x7684;&#x673A;&#x5236;
</code></pre><hr>
<h3 id="&#x4E09;&#x3001;kafka">&#x4E09;&#x3001;kafka</h3>
<p>&#xA0;&#xA0;&#xA0;&#xA0;Kafka&#x662F;&#x7531;Apache&#x8F6F;&#x4EF6;&#x57FA;&#x91D1;&#x4F1A;&#x5F00;&#x53D1;&#x7684;&#x4E00;&#x4E2A;&#x5F00;&#x6E90;&#x6D41;&#x5904;&#x7406;&#x5E73;&#x53F0;&#xFF0C;&#x7531;Scala&#x548C;Java&#x7F16;&#x5199;&#x3002;Kafka&#x662F;&#x4E00;&#x79CD;&#x9AD8;&#x541E;&#x5410;&#x91CF;&#x7684;&#x5206;&#x5E03;&#x5F0F;&#x53D1;&#x5E03;&#x8BA2;&#x9605;&#x6D88;&#x606F;&#x7CFB;&#x7EDF;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x5904;&#x7406;&#x6D88;&#x8D39;&#x8005;&#x89C4;&#x6A21;&#x7684;&#x7F51;&#x7AD9;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x52A8;&#x4F5C;&#x6D41;&#x6570;&#x636E;&#x3002; &#x8FD9;&#x79CD;&#x52A8;&#x4F5C;&#xFF08;&#x7F51;&#x9875;&#x6D4F;&#x89C8;&#xFF0C;&#x641C;&#x7D22;&#x548C;&#x5176;&#x4ED6;&#x7528;&#x6237;&#x7684;&#x884C;&#x52A8;&#xFF09;&#x662F;&#x5728;&#x73B0;&#x4EE3;&#x7F51;&#x7EDC;&#x4E0A;&#x7684;&#x8BB8;&#x591A;&#x793E;&#x4F1A;&#x529F;&#x80FD;&#x7684;&#x4E00;&#x4E2A;&#x5173;&#x952E;&#x56E0;&#x7D20;&#x3002;</p>
<pre><code>Broker: Kafka&#x96C6;&#x7FA4;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x8FD9;&#x79CD;&#x670D;&#x52A1;&#x5668;&#x88AB;&#x79F0;&#x4E3A;broker
Topic: &#x6BCF;&#x6761;&#x53D1;&#x5E03;&#x5230;Kafka&#x96C6;&#x7FA4;&#x7684;&#x6D88;&#x606F;&#x90FD;&#x6709;&#x4E00;&#x4E2A;&#x7C7B;&#x522B;&#xFF0C;&#x8FD9;&#x4E2A;&#x7C7B;&#x522B;&#x88AB;&#x79F0;&#x4E3A;Topic
Partition: Partition&#x662F;&#x7269;&#x7406;&#x4E0A;&#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x6BCF;&#x4E2A;Topic&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;Partition
Producer: &#x8D1F;&#x8D23;&#x53D1;&#x5E03;&#x6D88;&#x606F;&#x5230;Kafka broker
Consumer: &#x6D88;&#x606F;&#x6D88;&#x8D39;&#x8005;&#xFF0C;&#x5411;Kafka broker&#x8BFB;&#x53D6;&#x6D88;&#x606F;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x3002;
Consumer Group: &#x6BCF;&#x4E2A;Consumer&#x5C5E;&#x4E8E;&#x4E00;&#x4E2A;&#x7279;&#x5B9A;&#x7684;Consumer Group
</code></pre><h4 id="31-kafka&#x96C6;&#x7FA4;&#x642D;&#x5EFA;">3.1 kafka&#x96C6;&#x7FA4;&#x642D;&#x5EFA;</h4>
<p>&#xA0;&#xA0;&#xA0;&#xA0;&#x521B;&#x5EFA;docker-zk-kafka.yml&#x6587;&#x4EF6;&#x5982;&#x4E0B;&#xFF0C;&#x5E76;&#x6267;&#x884C;<code>docker-compose -f docker-zk-kafka.yml -d</code></p>
<pre><code class="lang-yml"><span class="hljs-attr">version:</span> <span class="hljs-string">&apos;2&apos;</span>
<span class="hljs-attr">services:</span>
<span class="hljs-attr">  zk:</span>
<span class="hljs-attr">    image:</span> docker.io/zookeeper:<span class="hljs-number">3.4</span><span class="hljs-number">.9</span>
<span class="hljs-attr">    hostname:</span> spero-zk-server
<span class="hljs-attr">    ports:</span>
<span class="hljs-bullet">      -</span> <span class="hljs-string">&quot;2181:2181&quot;</span>
<span class="hljs-attr">    environment:</span>
<span class="hljs-attr">        ZOO_MY_ID:</span> <span class="hljs-number">1</span>
<span class="hljs-attr">        ZOO_PORT:</span> <span class="hljs-number">2181</span>
<span class="hljs-attr">        ZOO_SERVERS:</span> server<span class="hljs-number">.1</span>=spero-zk-server:<span class="hljs-number">2888</span>:<span class="hljs-number">3888</span>
<span class="hljs-attr">    volumes:</span>
<span class="hljs-bullet">      -</span> ./zk-kafka-share/zk/data:/data
<span class="hljs-bullet">      -</span> ./zk-kafka-share/zk/datalog:/datalog
<span class="hljs-attr">  kafka1:</span>
<span class="hljs-attr">    image:</span> wurstmeister/kafka 
<span class="hljs-attr">    hostname:</span> kafka1
<span class="hljs-attr">    ports:</span>
<span class="hljs-bullet">      -</span> <span class="hljs-string">&quot;9092:9092&quot;</span>
<span class="hljs-bullet">      -</span> <span class="hljs-string">&quot;9999:9999&quot;</span>
<span class="hljs-attr">    environment:</span>
<span class="hljs-attr">      KAFKA_ADVERTISED_LISTENERS:</span> <span class="hljs-string">&quot;PLAINTEXT://spero-kafka-server:9092&quot;</span>
<span class="hljs-attr">      KAFKA_LISTENERS:</span> <span class="hljs-string">&quot;PLAINTEXT://:9092&quot;</span>
<span class="hljs-attr">      KAFKA_ZOOKEEPER_CONNECT:</span> <span class="hljs-string">&quot;spero-zk-server:2181&quot;</span>
<span class="hljs-attr">      KAFKA_BROKER_ID:</span> <span class="hljs-number">1</span>
<span class="hljs-attr">      KAFKA_LOG4J_LOGGERS:</span> <span class="hljs-string">&quot;kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO&quot;</span>
<span class="hljs-attr">      KAFKA_HEAP_OPTS:</span> <span class="hljs-string">&quot;-Xmx1G -Xms1G&quot;</span>
<span class="hljs-attr">      EXTRA_ARGS:</span> <span class="hljs-string">&quot;-name kafkaServer -loggc&quot;</span>
<span class="hljs-attr">      JMX_PORT:</span> <span class="hljs-number">9999</span>
<span class="hljs-attr">      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR:</span> <span class="hljs-number">1</span>
<span class="hljs-attr">    volumes:</span>
<span class="hljs-bullet">      -</span> ./zk-kafka-share/kafka1/data:/var/lib/kafka/data
<span class="hljs-attr">    depends_on:</span>
<span class="hljs-bullet">      -</span> zk
</code></pre>
<h4 id="32-&#x5E94;&#x7528;&#x4E3E;&#x4F8B;">3.2 &#x5E94;&#x7528;&#x4E3E;&#x4F8B;</h4>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> kafka = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;kafka-node&apos;</span>)

<span class="hljs-keyword">const</span> KeyedMessage = kafka.KeyedMessage
<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> kafka.KafkaClient({kafkaHost: <span class="hljs-string">&apos;127.0.0.1:9092&apos;</span>})
<span class="hljs-keyword">const</span> km = <span class="hljs-keyword">new</span> KeyedMessage(<span class="hljs-string">&apos;key&apos;</span>, <span class="hljs-string">&apos;message&apos;</span>)

<span class="hljs-keyword">const</span> Producer = kafka.Producer
<span class="hljs-keyword">const</span> Consumer = kafka.Consumer

<span class="hljs-keyword">const</span> producer = <span class="hljs-keyword">new</span> Producer(client)
<span class="hljs-keyword">const</span> consumer =  <span class="hljs-keyword">new</span> Consumer(client)

<span class="hljs-keyword">const</span> payloads = [
    { topic: <span class="hljs-string">&apos;topic1&apos;</span>, messages: <span class="hljs-string">&apos;hi&apos;</span>, partition: <span class="hljs-number">0</span> },
  { topic: <span class="hljs-string">&apos;topic2&apos;</span>, messages: [<span class="hljs-string">&apos;hello&apos;</span>, <span class="hljs-string">&apos;world&apos;</span>, km] }
]

producer.on(<span class="hljs-string">&apos;ready&apos;</span>, () =&gt; {
    setInterval(() =&gt; {
        producer.send(payloads, (err, data) =&gt; {
            <span class="hljs-keyword">if</span>(err) {
                <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;send data error&apos;</span>, err)
            }

            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;producer send data&apos;</span>, data)
        })
    }, <span class="hljs-number">1500</span>)
})

consumer.on(<span class="hljs-string">&apos;message&apos;</span>, (msg) =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;consume message from kafka&apos;</span>, msg)
})

producer.on(<span class="hljs-string">&apos;error&apos;</span>, (err) =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;producer error&apos;</span>, err)
})
</code></pre>
<ul>
<li>&#x65E5;&#x5FD7;&#x6570;&#x636E;&#x7F13;&#x51B2;&#x533A;</li>
<li>&#x961F;&#x5217;&#x670D;&#x52A1;</li>
</ul>
<h4 id="33-&#x9002;&#x7528;&#x573A;&#x666F;">3.3 &#x9002;&#x7528;&#x573A;&#x666F;</h4>
<p>1.&#x6D88;&#x606F;&#x961F;&#x5217;</p>
<pre><code>&#x6BD4;&#x8D77;&#x5927;&#x591A;&#x6570;&#x7684;&#x6D88;&#x606F;&#x7CFB;&#x7EDF;&#x6765;&#x8BF4;&#xFF0C;Kafka&#x6709;&#x66F4;&#x597D;&#x7684;&#x541E;&#x5410;&#x91CF;&#xFF0C;&#x5185;&#x7F6E;&#x7684;&#x5206;&#x533A;&#xFF0C;&#x5197;&#x4F59;&#x53CA;&#x5BB9;&#x9519;&#x6027;&#xFF0C;&#x8FD9;&#x8BA9;Kafka&#x6210;&#x4E3A;&#x4E86;&#x4E00;&#x4E2A;&#x5F88;&#x597D;&#x7684;&#x5927;&#x89C4;&#x6A21;&#x6D88;&#x606F;&#x5904;&#x7406;&#x5E94;
&#x7528;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002; &#x6D88;&#x606F;&#x7CFB;&#x7EDF;&#x4E00;&#x822C;&#x541E;&#x5410;&#x91CF;&#x76F8;&#x5BF9;&#x8F83;&#x4F4E;&#xFF0C;&#x4F46;&#x662F;&#x9700;&#x8981;&#x66F4;&#x5C0F;&#x7684;&#x7AEF;&#x5230;&#x7AEF;&#x5EF6;&#x65F6;&#xFF0C;&#x5E76;&#x5C1D;&#x5C1D;&#x4F9D;&#x8D56;&#x4E8E;Kafka&#x63D0;&#x4F9B;&#x7684;&#x5F3A;&#x5927;&#x7684;&#x6301;&#x4E45;&#x6027;&#x4FDD;&#x969C;&#x3002;&#x5728;&#x8FD9;
&#x4E2A;&#x9886;&#x57DF;&#xFF0C;Kafka&#x8DB3;&#x4EE5;&#x5AB2;&#x7F8E;&#x4F20;&#x7EDF;&#x6D88;&#x606F;&#x7CFB;&#x7EDF;&#xFF0C; &#x5982;ActiveMR&#x6216;RabbitMQ&#x3002;
</code></pre><p>2.&#x884C;&#x4E3A;&#x8DDF;&#x8E2A;</p>
<pre><code>Kafka&#x7684;&#x53E6;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x573A;&#x666F;&#x662F;&#x8DDF;&#x8E2A;&#x7528;&#x6237;&#x6D4F;&#x89C8;&#x9875;&#x9762;&#x3001;&#x641C;&#x7D22;&#x53CA;&#x5176;&#x4ED6;&#x884C;&#x4E3A;&#xFF0C;&#x4EE5;&#x53D1;&#x5E03;-&#x8BA2;&#x9605;&#x7684;&#x6A21;&#x5F0F;&#x5B9E;&#x65F6;&#x8BB0;&#x5F55;&#x5230;&#x5BF9;&#x5E94;&#x7684;topic&#x91CC;&#x3002;&#x90A3;&#x4E48;&#x8FD9;&#x4E9B;&#x7ED3;&#x679C;&#x88AB;&#x8BA2;
&#x9605;&#x8005;&#x62FF;&#x5230;&#x540E;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x505A;&#x8FDB;&#x4E00;&#x6B65;&#x7684;&#x5B9E;&#x65F6;&#x5904;&#x7406;&#xFF0C;&#x6216;&#x5B9E;&#x65F6;&#x76D1;&#x63A7;&#xFF0C;&#x6216;&#x653E;&#x5230;hadoop/&#x79BB;&#x7EBF;&#x6570;&#x636E;&#x4ED3;&#x5E93;&#x91CC;&#x5904;&#x7406;&#x3002;
</code></pre><p>3.&#x5143;&#x4FE1;&#x606F;&#x76D1;&#x63A7;</p>
<pre><code>&#x4F5C;&#x4E3A;&#x64CD;&#x4F5C;&#x8BB0;&#x5F55;&#x7684;&#x76D1;&#x63A7;&#x6A21;&#x5757;&#x6765;&#x4F7F;&#x7528;&#xFF0C;&#x5373;&#x6C47;&#x96C6;&#x8BB0;&#x5F55;&#x4E00;&#x4E9B;&#x64CD;&#x4F5C;&#x4FE1;&#x606F;&#xFF0C;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x4E3A;&#x8FD0;&#x7EF4;&#x6027;&#x8D28;&#x7684;&#x6570;&#x636E;&#x76D1;&#x63A7;&#x5427;&#x3002;
</code></pre><p>4.&#x65E5;&#x5FD7;&#x6536;&#x96C6;</p>
<pre><code>&#x65E5;&#x5FD7;&#x6536;&#x96C6;&#x65B9;&#x9762;&#xFF0C;&#x5176;&#x5B9E;&#x5F00;&#x6E90;&#x4EA7;&#x54C1;&#x6709;&#x5F88;&#x591A;&#xFF0C;&#x5305;&#x62EC;Scribe&#x3001;Apache Flume&#x3002;&#x5F88;&#x591A;&#x4EBA;&#x4F7F;&#x7528;Kafka&#x4EE3;&#x66FF;&#x65E5;&#x5FD7;&#x805A;&#x5408;&#xFF08;log aggregation&#xFF09;&#x3002;&#x65E5;&#x5FD7;&#x805A;
&#x5408;&#x4E00;&#x822C;&#x6765;&#x8BF4;&#x662F;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x6536;&#x96C6;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x653E;&#x5230;&#x4E00;&#x4E2A;&#x96C6;&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;&#xFF08;&#x6587;&#x4EF6;&#x670D;&#x52A1;&#x5668;&#x6216;HDFS&#xFF09;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x3002;&#x7136;&#x800C;Kafka&#x5FFD;&#x7565;&#x6389; &#x6587;&#x4EF6;&#x7684;&#x7EC6;&#x8282;
&#xFF0C;&#x5C06;&#x5176;&#x66F4;&#x6E05;&#x6670;&#x5730;&#x62BD;&#x8C61;&#x6210;&#x4E00;&#x4E2A;&#x65E5;&#x5FD7;&#x6216;&#x4E8B;&#x4EF6;&#x7684;&#x6D88;&#x606F;&#x6D41;&#x3002;&#x8FD9;&#x5C31;&#x8BA9;Kafka&#x5904;&#x7406;&#x8FC7;&#x7A0B;&#x5EF6;&#x8FDF;&#x66F4;&#x4F4E;&#xFF0C;&#x66F4;&#x5BB9;&#x6613;&#x652F;&#x6301;&#x591A;&#x6570;&#x636E;&#x6E90;&#x548C;&#x5206;&#x5E03;&#x5F0F;&#x6570;&#x636E;&#x5904;&#x7406;&#x3002;&#x6BD4;&#x8D77;
&#x4EE5;&#x65E5;&#x5FD7;&#x4E3A;&#x4E2D;&#x5FC3;&#x7684; &#x7CFB;&#x7EDF;&#x6BD4;&#x5982;Scribe&#x6216;&#x8005;Flume&#x6765;&#x8BF4;&#xFF0C;Kafka&#x63D0;&#x4F9B;&#x540C;&#x6837;&#x9AD8;&#x6548;&#x7684;&#x6027;&#x80FD;&#x548C;&#x56E0;&#x4E3A;&#x590D;&#x5236;&#x5BFC;&#x81F4;&#x7684;&#x66F4;&#x9AD8;&#x7684;&#x8010;&#x7528;&#x6027;&#x4FDD;&#x8BC1;&#xFF0C;&#x4EE5;&#x53CA;&#x66F4;&#x4F4E;&#x7684;&#x7AEF;&#x5230;
&#x7AEF;&#x5EF6;&#x8FDF;&#x3002;
</code></pre><ul>
<li>*<a href="https://www.rabbitmq.com/tutorials/tutorial-four-javascript.html" target="_blank">rabbit &#x5B98;&#x65B9;&#x6587;&#x6863;</a> </li>
</ul>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x4E00;&#x84D1;&#x70DF;&#x96E8;&#x4EFB;&#x5E73;&#x751F; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x4FEE;&#x6539;&#x65F6;&#x95F4;: 
2021-04-09 11:09:03
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="socket.html" class="navigation navigation-prev " aria-label="Previous page: 2.1 长连接">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../../program/" class="navigation navigation-next " aria-label="Next page: 3 语言应用">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"2.2 MQ","level":"1.3.2.2","depth":3,"next":{"title":"3 语言应用","level":"1.3.3","depth":2,"path":"program/README.md","ref":"program/README.md","articles":[{"title":"3.1 Node.js","level":"1.3.3.1","depth":3,"path":"program/nodejs/node.md","ref":"program/nodejs/node.md","articles":[{"title":"3.1.1 原理及构成","level":"1.3.3.1.1","depth":4,"path":"program/nodejs/core.md","ref":"program/nodejs/core.md","articles":[]},{"title":"3.1.2 异步机制","level":"1.3.3.1.2","depth":4,"path":"program/nodejs/async.md","ref":"program/nodejs/async.md","articles":[]},{"title":"3.1.3 一些核心概念","level":"1.3.3.1.3","depth":4,"path":"program/nodejs/important.md","ref":"program/nodejs/important.md","articles":[]},{"title":"3.1.4 web应用: koa框架","level":"1.3.3.1.4","depth":4,"path":"program/nodejs/koa_web.md","ref":"program/nodejs/koa_web.md","articles":[]},{"title":"3.1.5 koa源码分析","level":"1.3.3.1.5","depth":4,"path":"program/nodejs/koa.md","ref":"program/nodejs/koa.md","articles":[]},{"title":"3.1.6 libuv网络库应用","level":"1.3.3.1.6","depth":4,"path":"program/nodejs/libuv.md","ref":"program/nodejs/libuv.md","articles":[]},{"title":"3.1.7 性能调优","level":"1.3.3.1.7","depth":4,"path":"program/nodejs/apm.md","ref":"program/nodejs/apm.md","articles":[]},{"title":"3.1.8 其他: Node爬虫","level":"1.3.3.1.8","depth":4,"path":"program/nodejs/node_spider.md","ref":"program/nodejs/node_spider.md","articles":[]},{"title":"3.1.9 其他: Node编写Mapreduce","level":"1.3.3.1.9","depth":4,"path":"program/nodejs/node_map_reduce.md","ref":"program/nodejs/node_map_reduce.md","articles":[]}]},{"title":"3.2 C/C++","level":"1.3.3.2","depth":3,"path":"program/c/c_and_plus.md","ref":"program/c/c_and_plus.md","articles":[{"title":"3.2.1 面向对象","level":"1.3.3.2.1","depth":4,"path":"program/c/oop.md","ref":"program/c/oop.md","articles":[]},{"title":"3.2.2 进程通信","level":"1.3.3.2.2","depth":4,"path":"program/c/ipcs.md","ref":"program/c/ipcs.md","articles":[]},{"title":"3.2.3 线程管理","level":"1.3.3.2.3","depth":4,"path":"program/c/thread.md","ref":"program/c/thread.md","articles":[]},{"title":"3.2.4 内存管理","level":"1.3.3.2.4","depth":4,"path":"program/c/memory.md","ref":"program/c/memory.md","articles":[]},{"title":"3.2.5 网络编程","level":"1.3.3.2.5","depth":4,"path":"program/c/network.md","ref":"program/c/network.md","articles":[]},{"title":"3.2.6 构建工具","level":"1.3.3.2.6","depth":4,"path":"program/c/build_tool.md","ref":"program/c/build_tool.md","articles":[]},{"title":"3.2.7 其他: 线程池","level":"1.3.3.2.7","depth":4,"path":"program/c/thread_pool.md","ref":"program/c/thread_pool.md","articles":[]}]}]},"previous":{"title":"2.1 长连接","level":"1.3.2.1","depth":3,"path":"engineering/network_prag/socket.md","ref":"engineering/network_prag/socket.md","articles":[]},"dir":"ltr"},"config":{"plugins":["disqus","tree","splitter","local-video","chart","github-buttons","tbfed-pagefooter","ace","katex"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 一蓑烟雨任平生","modify_label":"修改时间: ","modify_format":"YYYY-MM-DD HH:mm:ss"},"disqus":{"useIdentifier":false,"shortName":"gitbookuse"},"ace":{},"splitter":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"katex":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"github-buttons":{"repo":"TIME-GATE/","types":["star","watch"],"size":"large"},"local-video":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"tree":{},"chart":{"type":"c3"}},"theme":"default","author":"zq_sdk@163.com","name":"name","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Ebook","language":"zh-hans","gitbook":"*","description":"电子书"},"file":{"path":"engineering/network_prag/mq.md","mtime":"2021-04-09T03:09:03.233Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-04-10T12:23:44.633Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.16.1/URI.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-disqus/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-tree/jquery.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-tree/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-ace/ace/ace.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-ace/ace.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

